package com.myplaylist.server;

import java.net.ServerSocket;
import java.net.Socket;

import com.myplaylist.utils.Constants;

public class TcpUserDataCollectorThread implements Runnable {

	private ServerSocket serverSocket;
	
	@Override
	public void run() {
		try {
			System.out.println("TCP service is up");
			Socket socket = null;
			serverSocket = new ServerSocket(Constants.TCP_SERVER_PORT);

			while(true) {
				socket = serverSocket.accept();
				System.out.println("Received new connection, starting TCP handler thread");
				TcpConnectionHandler tcpConnectionHandler = new TcpConnectionHandler(socket);
				tcpConnectionHandler.start();
			}
		} catch (Exception e) {
			System.err.println("Error while listening on port: " + Constants.TCP_SERVER_PORT);
			e.printStackTrace();
		}
	}

}
